package com.itheima.day01.managerTest.dao;

import com.itheima.day01.managerTest.domain.Teacher;

import java.util.ArrayList;

public class TeacherDaoTest {
    // private static ArrayList<Teacher> listTea = new ArrayList<>();
    private static Teacher[] arr = new Teacher[5];

    // 返回集合
    public ArrayList<Teacher> findAllTeacher(){
        ArrayList<Teacher> listTea = new ArrayList<>();
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] != null){
                listTea.add(arr[i]);
            }
        }
        return listTea;
    }

    // 添加老师
    public boolean addTeacher(Teacher addTea) {
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] != null){
                arr[i] = addTea;
                break;
            }
        }
        return true;
    }

    // 解雇老师
    public void deleteTeacherById(int index) {
        int indexs;
        for (indexs = index; indexs < arr.length - 1; indexs++) {
            arr[indexs] = arr[indexs + 1];
        }
        arr[indexs] = null;
    }

    // 修改老师
    public void updateTeacher(int index, Teacher teacher) {
        arr[index] = teacher;
        // listTea.set(index,teacher);
    }
}
